package com.itheima.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@Configuration
public class RedisConfig {
    
    
    @Bean
    public RedisTemplate redisTemplate(RedisConnectionFactory connectionFactory){
        
        //1. 自己new RedisTemplate
        RedisTemplate redisTemplate = new RedisTemplate();
        
        //2. 设置序列化器
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        redisTemplate.setValueSerializer(new StringRedisSerializer());
        
        redisTemplate.setHashKeySerializer(new StringRedisSerializer());
        redisTemplate.setHashValueSerializer(new StringRedisSerializer());
        
        //3. 设置连接工厂
        redisTemplate.setConnectionFactory(connectionFactory);
        
        return redisTemplate;
    }
}
